package springobjects;

import massobjects.BaseMass;


/**
 * Muscle extends spring. Changes rest length based on sin wave using extra
 * state variables.
 * 
 * @author David Howdyshell, Zack Hopping
 * 
 */
public class Muscle extends Spring {
    // state
    private double myLength;
    private double myAmplitude;
    private double myInitLength;
    
    /**
     * Constructor for muscle.
     * 
     * @param start - mass at start
     * @param end - mass at end
     * @param length - rest length
     * @param kVal - spring constant
     * @param amp - amplitude of sin wave.
     */
    public Muscle (BaseMass start, BaseMass end, double length, double kVal,
            double amp) {
        super(start, end, length, kVal);
        myLength = length;
        myInitLength = length;
        myAmplitude = amp;
    }

    @Override
    public void update (double dt) {
        setLength(dt);
        super.update(dt);
    }

    /**
     * Returns current muscle length.
     * 
     * @return myLength
     */
    public double getLength () {
        return myLength;
    }

    private void setLength (double dt) {
        myLength = myInitLength + myAmplitude * Math.sin((2 * Math.PI) * dt);
    }
}
